<?php

namespace app\common\model\info;
use app\common\model\BaseModel;
use app\common\repositories\lawyer\LawyerRepository;
use app\common\repositories\user\UserRepository;

class Question extends BaseModel
{

    public static function tablePK(): ?string
    {
        return 'question_id';
    }

    public static function tableName(): string
    {
        return 'question';
    }


    public function getUserInfoAttr()
    {
        if($this->getAttr('type') == 1){
            $user = app()->make(UserRepository::class)->get($this->uid);
            return [
                'name'=>$user->nickname,
                'avatar'=>$user->avatar,
            ];
        }else{
            $user = app()->make(LawyerRepository::class)->get($this->lawyer_id);
            return [
                'name'=>$user->name,
                'avatar'=>$user->avatar,
                'lawyer_id'=>$user->lawyer_id
            ];
        }
    }

}